home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / qbfe10.arc / EDITTEST.BAS < prev    next >
BASIC Source File  |  1987-11-27  |  16KB  |  378 lines

  1. '
  2. '                               EditField
  3. '
  4. '                              Version 1.0
  5. '
  6. '            (For Use With Microsoft's QuickBASIC Compiler V4.0)
  7. '
  8. '                        (C) 1987 By Tony Elliott
  9. '
  10. '
  11. '            Please refer any comments, bugs or suggestions to
  12. '
  13. '                            Tony Elliott  c/o
  14. '                    Programmer's Information Exchange
  15. '                             (404) 928-0033
  16. '
  17. '  Support for this routine as well as help, comments, suggestions..etc for
  18. 'any of your QuickBASIC projects can be found on Programmer's Information
  19. 'Exchange.  Financial support for this routine is not required.  As an
  20. 'alternative, I suggest becoming a supporting user of P.I.E. ($10 per year
  21. 'until Dec. 31).
  22. '
  23. '
  24. '  This routine is released into the Public Domain under the following
  25. 'conditions:
  26. '
  27. '       1) All files in this ARChive must be distributed in their
  28. '          ORIGINAL, UNMODIFIED form.  If you correct a bug, make an
  29. '          enhancement, please upload it to Programmer's Information
  30. '          Exchange BBS as a PRIVATE file for the Sysop.  After reviewing
  31. '          any changes, appropriate credit will be given in the documentation
  32. '          and a new release will be made through P.I.E.
  33. '
  34. '       2) The following files must be included in the distribution
  35. '          archive:
  36. '                    EDITFLD.BAS - Source Code for EditField
  37. '                   STATLINE.BAS - Source Code for Statline
  38. '                   EDITTEST.BAS - Test-bed Program & Documentation
  39. '                    HISTORY.DOC - Revision history
  40. '                     README.1ST - Special Instructions
  41. '
  42. '
  43. '                            Brief Description
  44. '
  45. '
  46. '  After trying many field editing routines available in the BBS circuit,
  47. 'shareware and public domain, I never found one that was a 'editor for all
  48. 'occassions.'  So, I decided to write EditField.
  49. '
  50. 'In designing the routine, I tried to keep two primary objectives in mind:
  51. '
  52. '    1) It had to suit almost all needs as a numeric field editor AND a
  53. '       text field editor, but had to be easily interchangable.
  54. '
  55. '    2) I wanted the programmer to be able to specify EXACTLY what type of
  56. '       data was to be returned by the routine (minimum/maximum values for
  57. '       numeric fields and if a nul/zero-value string was allowed) so a
  58. '       minimum of additional code would be required to check the validity of
  59. '       the data returned.
  60. '
  61. '
  62. '  The call to the EditField subprogram has only four arguments.  The rest of
  63. 'the required variables are defined in a "common block" statment.  More on
  64. 'that later.
  65. '
  66. '  EditField also calls a routine called "Statline" (included) to display
  67. 'error/status information of line 25.  If you do not like the way that
  68. 'EditField handles this, you may write your own StatLine subprogram for
  69. 'EditField to call.  Please look at the StatLine source code for more info on
  70. 'how this is currently being handled.
  71. '
  72. '  EditField is set apart from other field editors in several ways.  Most
  73. 'importantly (in my opinion), is the FORMAT$ argument.  FORMAT$ uses a
  74. 'sub-set of the BASIC's PRINT USING syntax so that the length of the field
  75. 'AND the exact display format is easily defined.
  76. '
  77. '  EditField funtions in either a text entry mode or numeric entry mode.
  78. 'This mode is determined by the FORMAT$ arguments.  This is described in more
  79. 'detail later.  First I am going to cover the arguments that are common to
  80. 'both modes and then I will describe the mode specific arguments and
  81. 'functions.  Please keep in mind that a few of the arguments have different
  82. 'functions and different valid values in each mode.
  83. '
  84. '
  85. '  Syntax:
  86. '
  87. '  CALL EditField(old$, ed$, format$, retflag%)
  88. '
  89. '
  90. 'The routine also requires the presence of a "common block" defining the
  91. 'other required variables.  Once defined, these variables are shared by the
  92. 'EditField routine so you do not have to specify them in a CALL statement
  93. 'with a seemingly endlist list of arguments.  The values of these common
  94. 'block variables can be changed anywhere in your main program module.
  95. '
  96. '  You do not necessarly need to know how the common block functions to use
  97. 'it.  Just copy the example below into your program.  It must be placed before
  98. 'any execuatable statements. A "DEFINT A-Z" must precede the common block
  99. 'statement.  All statements in QB4 are executable except for COMMON, CONST,
  100. 'DATA, DEFtype, DIM (for static arrays), OPTION BASE, REM, SHARED, STATIC,
  101. 'TYPE...END TYPE, and all Metacommands.
  102. '
  103. 'Common block syntax: (All variables are integers unless otherwise defined)
  104. '
  105. '  COMMON /editfld/ row, col, ucase, minval!, maxval!, justify,_
  106. '    padchar, keystat, kfg, kbg, krow, kcol, sfg, sbg, sfg, dbg, insmode,_
  107. '    nul, alarm
  108. '
  109. ' Please note that QuickBASIC v4.0 does not allow you to join multiple
  110. 'physical lines into one logical line using the underscore "_" character.
  111. 'It was done here for display purposes only.
  112. '
  113. '
  114. '  As you can see, there are many parameters assoicatied with this routine.
  115. 'There are also allot of features packed in here, so read on a bit before
  116. 'you get discouraged!
  117. '
  118. '
  119. '                     Variables Common to Both Modes
  120. '
  121. ' old$ - Any text to be edited.  If you are going to edit a numeric field
  122. '        and wish to pass a numeric argument to the routine, it must first
  123. '        be converted to a string.  (Example: old$=STR$(number))
  124. '
  125. '  ed$ - The edited data returned from the routine.  If you were editing a
  126. '        numeric field, you may convert the contents of ed$ back into a
  127. '        numeric variable.  (Example: number=val(ed$))
  128. '
  129. '  row \ The row and column of screen location where editing is to take
  130. '  col / place.  (Default is current cursor position).
  131. '
  132. '  sfg \ The foreground (sfg) and the background (sbg) colors of the field
  133. '  sbg / during editing.  (Default: sfg=0  sbg=7)
  134. '
  135. '  dfg \ The foreground and background colors that the field will be displayed
  136. '  dbg / in when the routine is exited.  (Default: dfg=7  dbg=0)
  137. '
  138. 'keystat - If set to a non-zero value, a status display will be available for
  139. '          the INSert key, CAPS lock, and NUMber lock keys.  If active, the
  140. '          following arguments must also be defined:
  141. '
  142. '          krow \ Row and column screen positon where the 9 character status
  143. '          kcol / display will be placed.
  144. '           kfg \ Foreground and background colors of the status display. If
  145. '           kbg / krow, kcol, kfg or kbg are not defined, keystat will be
  146. '                 disabled.
  147. '
  148. '
  149. 'retflag - The routine exit condition flag.  If the user exited normally
  150. '          (by pressing enter at the end of a valid field), it will be set
  151. '          to 0.  If the user aborted (pressed ESC), it will be set to 1.
  152. '          If an invalid format$ argument was used, 99 will be returned.
  153. '          If a value is returned other than those specified above, an
  154. '          "extended key" was pressed (one not used by the routine) and the
  155. '          code of that key is in retflag.
  156. '
  157. '  nul - If set to a non-zero value, the routine will not allow a nul (empty)
  158. '        string to be returned.  Or, if in the numeric mode, it will not
  159. '        allow a zero value to be returned (obeying minval!/maxval!).  This
  160. '        is useful where input would be REQUIRED (name or age). Default=0.
  161. '
  162. 'alarm - Set to a non-zero value to DISABLE the BEEP on errors.  You can
  163. '        define your own alarm sound by changing the "Alarm" subroutine in
  164. '        EDITFLD module.
  165. '
  166. '
  167. '                 Variables Specific to the Text Entry Mode
  168. '
  169. '
  170. 'format$ - To initiate the text entry mode, the first and last character of
  171. '          format$ must be the "\" (as in the PRINT USING syntax) with spaces
  172. '          in between.  The total length of format$ will be the maximim
  173. '          length of the field.  For example:
  174. '
  175. '          format$="\             \"   A 15 character text field
  176. '          format$="\\"                A 2 character text field
  177. '
  178. ' ucase = 0  No case conversion is performed.
  179. '       = 1  FORCES ALL UPPER CASE
  180. '       = 2  forces all lower case
  181. '
  182. 'justify= 0  No justification is performed.  The string is returned without
  183. '            any "padding" spaces on either side.  The returned string and
  184. '            the displayed field are both affected by 1,2 and 3 below.
  185. '       = 1  String is returned "Left Justified" (spaces fill the remaining
  186. '            length of the field - the text entered is on the LEFT side).
  187. '       = 2  String is returned "Right Justified."  Justification will not
  188. '            occur until the routine is exited.
  189. '       = 3  String is returned centered (and displayed centered). Again,
  190. '            centering will not occur until the routine is exited.
  191. '
  192. 'insmode - If set to a non-zero, the insert mode will be toggled ON upon
  193. '          entering the routine.  While ON, the cursor in the form of a solid
  194. '          block, and when OFF in the form of a flat line.
  195. '          Editing will begin from the left side of an existing field upon
  196. '          entering the routine with this toggled ON, and from the right side
  197. '          if OFF (personal preference).
  198. '
  199. 'padchar - Set this to the ascii value of the character to be used to fill in
  200. '          "empty" spaces in the field.  Default=32 (space)
  201. '
  202. '          (minval! / maxval! are ignored while in the text mode)
  203. '
  204. '
  205. '
  206. '                 Variables Specific to the Numeric Mode
  207. '
  208. 'format$ - In order to invoke the numeric mode, the first character of format$
  209. '          must be "#".  The only valid characters allowed in format$ when
  210. '          defining a numeric field is "#" and "."   When exiting the routine,
  211. '          any values entered will be displayed using format$ just as if the
  212. '          value have been displayed via PRINT USING.
  213. '          Valid example are:
  214. '
  215. '              format$="###.##"  - Will allow entry of values from 0 to 999
  216. '                                  obeying minval!/maxval! and nul.  Upon
  217. '                                  exiting the routine, the value entered
  218. '                                  will be displayed using this format.
  219. '
  220. '              format$="#####"   - Allow values from 0 to 99,999.  If a
  221. '                                  decimal is entered, the routine will accept
  222. '                                  it, but will round the value off to an
  223. '                                  integer.
  224. '
  225. '          A couple of things to keep in mind .. minval!/maxval! have priority
  226. '          over the routine's built-in min/max value calculation.  Be sure
  227. '          you do not define a maxval! greater that the format$'s ability to
  228. '          display.  Also, the range of allowable numeric entry is confined to
  229. '          BASIC's limitations on single percision variables.
  230. '
  231. ' minval! \ Defines the minimum and maximum allowable values for entry. The
  232. ' maxval! / use must enter a value with this range or abort (ESC).
  233. '
  234. '    nul - If set to a non-zero, the routine will only accept a non-zero value
  235. '          obeying minval!/maxval!.  Default=0
  236. '
  237. '
  238. '********* Please Note: The functions of the following two arguments
  239. '          differ from the text mode!
  240. '
  241. 'justify - If set to a non-zero, the special numeric formatting will be
  242. '          removed from ed$.  The field will still display the value according
  243. '          to format$. Default=0
  244. '
  245. '  ucase - If set to a non-zero and a value was assigned to old$ to be edited,
  246. '          the "old" value will be erased at the first valid keystroke.
  247. '          The user would have to enter the new value from scratch.  If set to
  248. '          0, text mode type editing is available.
  249. '
  250. '                (padchar is ignored in the numeric mode)
  251. '
  252. '
  253. '
  254. '                         Valid Editing Keys
  255. '
  256. ' Left Arrow - Move cursor to left one character
  257. '
  258. ' Right Arrow - Move cursor to right one character
  259. '
  260. ' Home - Move cursor to left side of field
  261. '
  262. ' End - Move cursor to right side of field
  263. '
  264. ' Ins - Toggles the insert mode ON/OFF.  Cursor is a block shape when ON.
  265. '
  266. ' Del - Deletes character at cursor position.  All characters to the right of
  267. '       the cursor are moved to the left one space.
  268. '
  269. '(Backspace) - Deletes the character to the left of the cursor. All char-
  270. '       acters at, and to the right of the cursor will be moved to the
  271. '       left one space.
  272. '
  273. ' Cntrl-Right Arrow - Move to the right one word.
  274. '
  275. ' Cntrl-Left Arrow - Move to the left one word.
  276. '
  277. ' Cntrl-Home - Deletes the contents of the field.
  278. '
  279. ' (Enter) - Exits the routine if the contents of field are within the
  280. '           parameters defined in the arguments.  Sets retflag to 0
  281. '
  282. ' (Esc) -   If the current contents of the field differs from old$, the
  283. '           original field contents are restored (acts as an UNDO key).
  284. '           If pressed a second consecutive time (or if the current contents
  285. '           of the field matchs old$) the routine will abort, setting
  286. '           retflag to 1
  287. '
  288. '
  289. '****************************************************************************
  290. '                            W A R N I N G ! !
  291. '
  292. '  EditField uses three routines from the ADVBAS 3.42 library (not included).
  293. '
  294. 'XQPRINT - Routine for direct screen writes        > In XQPRINT.OBJ
  295. 'SETKBD  - Set the CAPS, INS, NUM lock key mode    \ Both of these routines
  296. 'GETKBD  - Get the CAPS, INS, NUM lock key status  / are in KBD.OBJ
  297. 'CALCATTR- Calculates screen color attributes      > In CALCATTR.OBJ
  298. '
  299. '  Be sure to include these in your .LIB & .QLB libraries before attempting to
  300. 'run these routines.
  301. '
  302. '  There have been reports that some of the ADVBAS routines written for
  303. 'QB2 & QB3 are not compatible with QB4.  Although I have tested these routines
  304. '(specifically XQPRINT, SETKBD, GETKBD) in programs of various sizes without
  305. 'problem, I strongly suggest you replace these routines with ones written for
  306. 'QB4 (ProBAS by Hammerly Computer Services, Inc, HIGHLY recommended).
  307. '
  308. '*****************************************************************************
  309.  
  310. ' Please keep in mind.. this is just a "shell" to get you started.  It is not
  311. 'intended to be an elaborate demo of EditField.
  312.  
  313.  
  314.  
  315. DEFINT A-Z
  316.  
  317. COMMON /editfld/ row, col, ucase, minval!, maxval!, justify, padchar, keystat, kfg, kbg, krow, kcol, sfg, sbg, dfg, dbg, insmode, nul, alarm
  318.  
  319. DECLARE SUB EditField (old$, ed$, format$, retflag)
  320. 'Just a basic set-up to get things rolling...
  321.  
  322. 'row=10 : col=20          'Field position (Disabled. Uses current cursor pos)
  323. sfg = 4: sbg = 7          'Editing colors
  324. dfg = 14: dbg = 0         'Display colors (used when exiting routine)
  325. keystat = 1               'Turn on key status display
  326. kfg = 9: kbg = 0          'Colors of the key status display
  327. krow = 1: kcol = 70       'Position of the key status display
  328. insmode = 0               'Insert OFF
  329. alarm = 0                 'Error alarm ON              
  330.  
  331. ' Main Program
  332.  
  333. CLS
  334. LOCATE 3, 15: PRINT "You may now edit this field.  Please refer to the"
  335. LOCATE 4, 15: PRINT "EDITTEST.BAS file for editing instructions"
  336.  
  337. 'Edit a text field
  338. COLOR 6, 0
  339. LOCATE 10, 1
  340. PRINT "Your Favorite BBS: ";
  341. old$ = "Programmer's Information Exchange"
  342. format$ = "\                                  \"
  343. padchar = 254
  344. justify = 0
  345. CALL EditField(old$, ed$, format$, retflag)
  346. GOSUB ShowResults
  347.  
  348. 'Edit a numeric field
  349. LOCATE 12, 1
  350. PRINT "Approximate Cost of Your Computer: $";
  351. old$ = "1295.50"
  352. ucase = 1
  353. format$ = "####.##"
  354. minval! = 100
  355. maxval! = 9999.99
  356. CALL EditField(old$, ed$, format$, retflag)
  357. GOSUB ShowResults
  358.  
  359. END
  360. '
  361. '****************************************************************************
  362. '                            PROGRAM SUBROUTINES
  363. '****************************************************************************
  364. '
  365.  
  366. 'Prints results
  367.  
  368. ShowResults:
  369.     COLOR 7, 0
  370.     LOCATE 18, 1
  371.     PRINT SPC(79);
  372.     LOCATE 18, 1
  373.     PRINT "String Returned: "; : COLOR 6: PRINT ed$
  374.     COLOR 7
  375.     PRINT "RETFLAG="; : COLOR 6: PRINT retflag
  376. RETURN
  377.  
  378.